{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 9.4.1 Kinetics動画のダウンロード\n",
    "\n",
    "本ファイルでは、Kinetics動画をダウンロードします。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 解説"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://github.com/activitynet/ActivityNet/tree/master/Crawler/Kinetics\n",
    "\n",
    "のKineticsの動画ダウンロード環境を利用します。\n",
    "\n",
    "Python2系なので、新しい仮想環境を作成します。\n",
    "今いるディレクトリはUbuntuのhomeです。\n",
    "\n",
    "以下のコマンドをターミナルで実行し、フォルダ「video_download」のファイル「environment.yml」に記載したパッケージをインストールした仮想環境を作成します\n",
    "\n",
    "- source deactivate\n",
    "\n",
    "- conda env create -f ./9_video_classification_eco/video_download/environment.yml\n",
    "\n",
    "作成した仮想環境に入ります\n",
    "\n",
    "- source activate kinetics\n",
    "\n",
    "youtube-dlのパッケージを更新インストールします\n",
    "\n",
    "- pip install --upgrade youtube-dl\n",
    "\n",
    "- pip install --upgrade joblib\n",
    "\n",
    "これで準備ができたので、JupyteNotebookを立ち上げ、本ファイルを実行します\n",
    "\n",
    "- jupyter notebook --port 9999\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/tmp/kinetics/61598a2a-008c-4be8-b905-675577ef7975.%(ext)s\n",
      "/tmp/kinetics/dda1d025-c5a0-4eaa-a1fa-7741e7b974c2.%(ext)s\n",
      "/tmp/kinetics/aee74f62-b200-4464-84c0-977f56b48830.%(ext)s\n",
      "/tmp/kinetics/9aa81f6a-b58c-4eae-8a28-b8a8e0f56f6d.%(ext)s\n",
      "/tmp/kinetics/1ea6c6cc-0253-4976-a51d-4812e2a61e44.%(ext)s\n",
      "/tmp/kinetics/9f855b52-7a6f-4781-a53f-a21e7ebbf938.%(ext)s\n",
      "/tmp/kinetics/bfca0f36-1499-4391-bb63-9f2c84a72d41.%(ext)s\n",
      "/tmp/kinetics/2c94b95d-14f4-410b-b60c-28834d2a7439.%(ext)s\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "# フォルダ「data」が存在しない場合は作成する\n",
    "data_dir = \"./data/\"\n",
    "if not os.path.exists(data_dir):\n",
    "    os.mkdir(data_dir)\n",
    "    \n",
    "# フォルダ「kinetics_videos」が存在しない場合は作成する\n",
    "data_dir = \"./data/kinetics_videos/\"\n",
    "if not os.path.exists(data_dir):\n",
    "    os.mkdir(data_dir)\n",
    "    \n",
    "    \n",
    "# フォルダ「video_download」のpytnonファイル「download.py」を実行します\n",
    "# 取得するyoutubeデータはフォルダ「video_download」のkinetics-400_val_8videos.csvに記載した8動画です\n",
    "# 保存先はフォルダ「data」内のフォルダ「kinetics_videos」です\n",
    "!python2 ./video_download/download.py ./video_download/kinetics-400_val_8videos.csv ./data/kinetics_videos/\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "以上"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
